package com.athuahua.mq.config;

import lombok.Data;
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.rabbit.transaction.RabbitTransactionManager;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Author: huahua
 * @Date: 2024/9/6 0006
 * @Time: 15:02
 * @Description:
 */
@Configuration
@Data
public class RabbitTxConfig {
    @Bean
    public RabbitTransactionManager transactionManager(CachingConnectionFactory factory){
        return new RabbitTransactionManager(factory);
    }


    @Bean
    public RabbitTemplate rabbitTemplate(CachingConnectionFactory factory){
        RabbitTemplate rabbitTemplate = new RabbitTemplate(factory);
        rabbitTemplate.setChannelTransacted(true);
        return rabbitTemplate;
    }
}
